package com.io.model;

import com.io.util.NettyUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;

import java.util.Date;

/**
 * Created by yangyx on 2016/7/27.
 * 汽车向服务端注册的实体类
 */
public class RegisterReq extends BaseModel {

    public static final int totalLength=37;

    public int id;            //表格主键
    public String vin;       //车辆的VIN 17个字符
    public String terminalID;       //终端ID 10个字符
    public String password;  //登录密码 10个字符
    public String new_password; //新密码
    public int result;       //返回状态
    public ChannelHandlerContext ctx;
    public Date registerDate;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getVin() {
        return vin;
    }
    public void setVin(String vin) {
        this.vin = vin;
    }
    public String getTerminalID() {
        return terminalID;
    }
    public void setTerminalID(String terminalID) {
        this.terminalID = terminalID;
    }

    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getNew_password() {
        return new_password;
    }
    public void setNew_password(String new_password) {
        this.new_password = new_password;
    }
    public int getResult() {
        return result;
    }
    public void setResult(int result) {
        this.result = result;
    }

    public ChannelHandlerContext getCtx() {
        return ctx;
    }
    public void setCtx(ChannelHandlerContext ctx) {
        this.ctx = ctx;
    }
    public Date getRegisterDate() {
        return registerDate;
    }
    public void setRegisterDate(Date registerDate) {
        this.registerDate = registerDate;
    }

    public static RegisterReq fromByteBuf(ByteBuf buf, int packageLength){
        if(packageLength<totalLength){
                return null;
        }else{
            RegisterReq registerReq=new RegisterReq();
            registerReq.vin= NettyUtils.readStringFromByteBuf(buf,17);
            registerReq.terminalID=NettyUtils.readStringFromByteBuf(buf,10);
            registerReq.password=NettyUtils.readStringFromByteBuf(buf,10);

            buf.discardReadBytes();
            return registerReq;
        }
    }

}
